//TOWN SCRIPT TEMPLATE

begintownscript;

variables;
int i;
string dlgstr;

body;

beginstate INIT_STATE;
	set_crime_tolerance(1);

if (get_flag(6,5)) {
	erase_char(6);
	activate_hidden_group(2);
	erase_char(15);
	}

	set_name(6,"Machrone");
	set_name(7,"Innkeeper");
	set_name(8,"Jenneke");
	set_name(9,"Thissa");
	set_name(10,"Frrrrrr");
	set_name(13,"Adrianna");
	set_name(12,"Feodoric");
	set_name(11,"Michael");
	set_name(14,"Robin");
	set_name(15,"Mysterious Wizard");
	set_name(17,"Soldier");
	set_name(18,"Soldier");
	set_name(19,"Priest");
	set_name(22,"Townsman");
	set_name(24,"Machrone");
break;

beginstate EXIT_STATE;
//called when the party leaves the town
	text_bubble_on_char(0,"");
	text_bubble_on_char(1,"");
	text_bubble_on_char(2,"");
	text_bubble_on_char(3,"");

break;

beginstate START_STATE;
//called every turn when the party is in the town

if (get_ran(1,0,100) < 3)
	text_bubble_on_char(1,"*scratch*");
if (get_ran(1,0,100) < 3)
	text_bubble_on_char(1,"*belch*");

if (get_ran(1,0,100) < 3)
	text_bubble_on_char(2,"omg!!");
if (get_ran(1,0,100) < 3)
	text_bubble_on_char(2,"*giggle*");

if (get_ran(1,0,100) < 3)
	text_bubble_on_char(3,"*grumble*");

if (get_flag(3,1) == 0) {
	if (get_ran(1,0,100) < 7)
		text_bubble_on_char(6,"Adventurers! Neat!");
	if (get_ran(1,0,100) < 7)
		text_bubble_on_char(6,"Come and talk to me!");
	}

if (get_ran(1,0,100) < 7)
	text_bubble_on_char(7,"Have a drink!");

if (get_ran(1,0,100) < 7)
	text_bubble_on_char(20,"*laugh*");
if (get_ran(1,0,100) < 7)
	text_bubble_on_char(21,"So then I say,");
if (get_ran(1,0,100) < 7)
	text_bubble_on_char(22,"*laugh*");

if (get_ran(1,0,100) < 7)
	text_bubble_on_char(16,"That reminds me...");
if (get_ran(1,0,100) < 7)
	text_bubble_on_char(16,"And then...!");

break;

beginstate 10;
if (get_flag(0,2))
	end();
if (get_flag(0,1) == 0)
	end();
	
	while (i < 119) {
	if (char_ok(i))
		text_bubble_on_char(i,"");
	i = i + 1;
	}

	block_entry(1);
	reset_dialog();
	add_dialog_str(0,"You have reached your room. What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Rest for the night.");
	if (run_dialog(1) == 1)
		end();
	
	set_flag(0,2,1);
	message_dialog("You break into pairs corresponding to your rooms and prepare for bed.","");
	
	set_character_facing(0,0);
	set_character_facing(1,2);
	set_character_facing(2,2);
	set_character_facing(3,0);
	relocate_character(0,6,7);
	relocate_character(1,31,31);
	relocate_character(2,32,31);
	relocate_character(3,9,7);
	force_view_center(8,9);
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));

	text_bubble_on_char(0,"How are you doing,");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	clear_buffer();
	append_char_name(3);
	append_string("?");
	get_buffer_text(dlgstr);

	text_bubble_on_char(0,"");
	text_bubble_on_char(0,dlgstr);
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	clear_buffer();
	append_string("Gods, ");
	append_char_name(0);
	append_string(",");
	get_buffer_text(dlgstr);

	text_bubble_on_char(0,"");
	text_bubble_on_char(3,dlgstr);
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	text_bubble_on_char(3,"do you EVER stop talking?!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	text_bubble_on_char(3,"Just shut up and let me sleep!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");

	message_dialog("Meanwhile, in the other room....","");
	
	relocate_character(0,31,31);
	relocate_character(1,13,9);
	relocate_character(2,13,7);
	relocate_character(3,32,31);
	force_view_center(14,9);
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));

	text_bubble_on_char(2,"What do you think,");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	clear_buffer();
	append_char_name(1);
	append_string(",");
	get_buffer_text(dlgstr);

	text_bubble_on_char(2,"");
	text_bubble_on_char(2,dlgstr);
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(2,"");
	text_bubble_on_char(2,"does this Fine Leather Armor");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(2,"");
	text_bubble_on_char(2,"make me look fat?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(2,"");
	text_bubble_on_char(1,"*burp*");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(1,"");
	text_bubble_on_char(1,"*scratch*");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(1,"");
	text_bubble_on_char(2,"Come on, I'm serious!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(2,"");
	text_bubble_on_char(2,"I think it makes my hips look bulgy.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(2,"");
	text_bubble_on_char(2,"Don't you?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(2,"");
	text_bubble_on_char(1,"*belch*");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(1,"");
	text_bubble_on_char(2,"Oh, you're no help!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(2,"");
	text_bubble_on_char(2,"*sigh*");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(2,"");
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));
	
	relocate_character(0,31,31);
	relocate_character(1,31,32);
	relocate_character(2,31,33);
	relocate_character(3,31,34);
	force_view_center(8,9);
	force_instant_terrain_redraw();
	pause(1 * get_flag(290,0));

	message_dialog("You settle down for sleep. Strange dreams haunt you all night, dreams of an underground empire of reptile-men, and of a soft, sibilant, feminine voice calling to you, calling to you, over and over, asking you to finish the mission that has been begun.","Then, in the middle of the night....");

	play_sound(159);
	pause(4 * get_flag(290,0));

	play_sound(9);
	pause(2 * get_flag(290,0));

	play_sound(160);
	pause(2 * get_flag(290,0));

	play_sound(59);
	pause(4 * get_flag(290,0));

	play_sound(72);
	play_sound(71);
	play_sound(102);
	play_sound(72);
	play_sound(54);
	play_sound(157);
	play_sound(65);
	play_sound(118);
	play_sound(69);
	play_sound(63);
	pause(4 * get_flag(290,0));

	play_sound(10);
	pause(4 * get_flag(290,0));

	message_dialog("The silence is deafening. You and your roommate leap to your feet, ready to face any intruders.","");
	
	set_character_facing(0,4);
	set_character_facing(1,2);
	set_character_facing(2,2);
	set_character_facing(3,4);
	relocate_character(0,6,7);
	relocate_character(1,31,31);
	relocate_character(2,32,31);
	relocate_character(3,9,7);
	force_view_center(8,9);
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	clear_buffer();
	append_string("_A lot of that noise came from the room across from us,_ says ");
	append_char_name(2);
	append_string(". _I don't know what happened._ You suppose that you should go check it out.");
	get_buffer_text(dlgstr);

	message_dialog("A knocking comes from your door, and you answer it. It's the other two members of your party!",dlgstr);

	move_to_new_town(3,7,9);

break;

beginstate 11;
if (get_flag(0,3))
	end();
	
	while (i < 119) {
	if (char_ok(i))
		text_bubble_on_char(i,"");
	i = i + 1;
	}
	
	set_flag(0,3,1);
	block_entry(1);
	message_dialog("Before you can take another step, you hear the clanking of armor and the rustling of robes behind you. Six heavily armed individuals are coming through the door.","");
	activate_hidden_group(1);
	force_instant_terrain_redraw();

	if (get_terrain(20,18) == 11) {
		set_terrain(20,18,15);
		force_instant_terrain_redraw();
		play_sound(58);
		}
	
	relocate_character(8,19,18);
	relocate_character(9,20,18);
	relocate_character(10,21,18);
	relocate_character(13,22,18);
	relocate_character(12,23,18);
	relocate_character(11,24,18);
	force_instant_terrain_redraw();
	play_sound(50);
	pause(1 * get_flag(290,0));

	i = 0;
	while (char_ok(i) == 0)
		{i = i + 1; }

	if ((char_loc_y(i) != 18) && (char_loc_y(i) != 19)) {
		relocate_character(8,18,18);
		relocate_character(9,19,18);
		relocate_character(10,20,18);
		relocate_character(13,21,18);
		relocate_character(12,22,18);
		relocate_character(11,23,18);
		force_instant_terrain_redraw();
		play_sound(50);
		pause(1 * get_flag(290,0));
		
		relocate_character(8,17,18);
		relocate_character(9,18,18);
		relocate_character(10,19,18);
		relocate_character(13,20,18);
		relocate_character(12,21,18);
		relocate_character(11,22,18);
		force_instant_terrain_redraw();
		play_sound(50);
		pause(1 * get_flag(290,0));
		
		relocate_character(8,16,18);
		relocate_character(9,17,18);
		relocate_character(10,18,18);
		relocate_character(13,19,18);
		relocate_character(12,20,18);
		relocate_character(11,21,18);
		force_instant_terrain_redraw();
		play_sound(50);
		pause(1 * get_flag(290,0));
		
		relocate_character(8,15,18);
		relocate_character(9,16,18);
		relocate_character(10,17,18);
		relocate_character(13,18,18);
		relocate_character(12,19,18);
		relocate_character(11,20,18);
		force_instant_terrain_redraw();
		play_sound(50);
		pause(1 * get_flag(290,0));
		
		relocate_character(8,14,18);
		relocate_character(9,15,18);
		relocate_character(10,16,18);
		relocate_character(13,17,18);
		relocate_character(12,18,18);
		relocate_character(11,19,18);
		force_instant_terrain_redraw();
		play_sound(50);
		pause(1 * get_flag(290,0));
		
		if (char_loc_y(i) > 19) {
			set_character_facing(0,0);
			set_character_facing(1,0);
			set_character_facing(2,0);
			set_character_facing(3,0);

			set_character_facing(8,4);
			set_character_facing(9,4);
			set_character_facing(10,4);
			set_character_facing(13,4);
			set_character_facing(12,4);
			set_character_facing(11,4);
			force_instant_terrain_redraw();
			pause(1 * get_flag(290,0));
			}
		else {
			set_character_facing(0,4);
			set_character_facing(1,4);
			set_character_facing(2,4);
			set_character_facing(3,4);

			set_character_facing(8,0);
			set_character_facing(9,0);
			set_character_facing(10,0);
			set_character_facing(13,0);
			set_character_facing(12,0);
			set_character_facing(11,0);
			force_instant_terrain_redraw();
			pause(1 * get_flag(290,0));
			}
		}
	else {
		set_character_facing(8,0);
		relocate_character(8,19,17);
		relocate_character(9,19,18);
		relocate_character(10,20,18);
		relocate_character(13,21,18);
		relocate_character(12,22,18);
		relocate_character(11,23,18);
		force_instant_terrain_redraw();
		play_sound(50);
		pause(1 * get_flag(290,0));
		
		set_character_facing(9,0);
		relocate_character(8,19,16);
		relocate_character(9,19,17);
		relocate_character(10,19,18);
		relocate_character(13,20,18);
		relocate_character(12,21,18);
		relocate_character(11,22,18);
		force_instant_terrain_redraw();
		play_sound(50);
		pause(1 * get_flag(290,0));
		
		set_character_facing(8,1);
		set_character_facing(10,0);
		relocate_character(8,18,15);
		relocate_character(9,19,16);
		relocate_character(10,19,17);
		relocate_character(13,19,18);
		relocate_character(12,20,18);
		relocate_character(11,21,18);
		force_instant_terrain_redraw();
		play_sound(50);
		pause(1 * get_flag(290,0));
		
		set_character_facing(8,2);
		set_character_facing(9,1);
		set_character_facing(13,0);
		relocate_character(8,17,15);
		relocate_character(9,18,15);
		relocate_character(10,19,16);
		relocate_character(13,19,17);
		relocate_character(12,19,18);
		relocate_character(11,20,18);
		force_instant_terrain_redraw();
		play_sound(50);
		pause(1 * get_flag(290,0));
		
		set_character_facing(9,2);
		set_character_facing(10,1);
		set_character_facing(12,0);
		relocate_character(8,16,15);
		relocate_character(9,17,15);
		relocate_character(10,18,15);
		relocate_character(13,19,16);
		relocate_character(12,19,17);
		relocate_character(11,19,18);
		force_instant_terrain_redraw();
		play_sound(50);
		pause(1 * get_flag(290,0));
		
		set_character_facing(10,2);
		set_character_facing(13,1);
		set_character_facing(11,0);
		relocate_character(8,15,15);
		relocate_character(9,16,15);
		relocate_character(10,17,15);
		relocate_character(13,18,15);
		relocate_character(12,19,16);
		relocate_character(11,19,17);
		force_instant_terrain_redraw();
		play_sound(50);
		pause(1 * get_flag(290,0));
		
		set_character_facing(13,2);
		set_character_facing(12,1);
		relocate_character(8,14,15);
		relocate_character(9,15,15);
		relocate_character(10,16,15);
		relocate_character(13,17,15);
		relocate_character(12,18,15);
		relocate_character(11,19,16);
		force_instant_terrain_redraw();
		play_sound(50);
		pause(1 * get_flag(290,0));
		
		set_character_facing(11,0);
		relocate_character(11,19,15);
		force_instant_terrain_redraw();
		play_sound(50);
		pause(1 * get_flag(290,0));

		set_character_facing(0,0);
		set_character_facing(1,0);
		set_character_facing(2,0);
		set_character_facing(3,0);
		
		set_character_facing(8,4);
		set_character_facing(9,4);
		set_character_facing(10,4);
		set_character_facing(13,4);
		set_character_facing(12,4);
		set_character_facing(11,4);
		force_instant_terrain_redraw();
		pause(1 * get_flag(290,0));
		}
	
	message_dialog("You size them up as they enter. They look like adventurers, too, and they're not much stronger than you, maybe level 5. There are six of them, though. They look quite bedraggled and scruffy. (You suddenly realize you probably look pretty scruffy, too.)","The leader, an axe-wielding, flame-haired man, looks you over very thoroughly, too.");

	text_bubble_on_char(8,"*look*");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(8,"");
	force_instant_terrain_redraw();

	message_dialog("You suddenly become conscious of the fact that you are a motley foursome of adventurers. Neither impressive in appearance nor strong in words, you look every bit the newcomer bunch that you are. Their leader nods, recognizing this.","Then he barks a word at you.");

	text_bubble_on_char(8,"Name?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(8,"");
	force_instant_terrain_redraw();
	
	message_dialog("You feel a sudden compulsion to tell this man everything about yourself. Words spill from you without your control.","");
	
	clear_buffer();
	append_string("My name is ");
	append_char_name(0);
	append_string(".");
	get_buffer_text(dlgstr);
	text_bubble_on_char(0,dlgstr);
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	clear_buffer();
	append_char_name(1);
	append_string(". *burp*");
	get_buffer_text(dlgstr);
	text_bubble_on_char(0,"");
	text_bubble_on_char(1,dlgstr);
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	clear_buffer();
	append_string("I'm ");
	append_char_name(2);
	append_string("!");
	get_buffer_text(dlgstr);
	text_bubble_on_char(1,"");
	text_bubble_on_char(2,dlgstr);
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	clear_buffer();
	append_string("I am ");
	append_char_name(3);
	append_string(".");
	get_buffer_text(dlgstr);
	text_bubble_on_char(2,"");
	text_bubble_on_char(3,dlgstr);
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	force_instant_terrain_redraw();

	message_dialog("Their leader takes a moment, internalizing this response. Then he barks another word.","");

	text_bubble_on_char(8,"Job?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));
	
	text_bubble_on_char(8,"");
	force_instant_terrain_redraw();
	
	message_dialog("Again you feel the compulsion to tell him your life story.","");

	text_bubble_on_char(0,"We are adventurers!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	text_bubble_on_char(0,"We go on quests, and fight monsters,");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	text_bubble_on_char(0,"and recover great treasure!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	text_bubble_on_char(3,"We're currently looking");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	text_bubble_on_char(3,"for our first quest.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	clear_buffer();
	append_string("Hush, ");
	append_char_name(3);
	append_string("!");
	get_buffer_text(dlgstr);

	text_bubble_on_char(3,"");
	text_bubble_on_char(0,dlgstr);
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	text_bubble_on_char(0,"We are GREAT adventurers. FAMOUS.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	force_instant_terrain_redraw();

	message_dialog("Their leader again takes a moment to process this reply. He looks a bit skeptical at that last claim. Then, apparently satisfied, he and his entire group march back out of the inn.","");

	erase_char(8);
	erase_char(9);
	erase_char(10);
	erase_char(13);
	erase_char(12);
	erase_char(11);
	force_instant_terrain_redraw();

	message_dialog("How odd.","");
	
break;

beginstate 12;
if (get_flag(0,4) == 0) {
	reset_dialog();
	add_dialog_str(0,"Ah, an inn, where the weary can rest. It looks well-kept and clean, and the patrons appear friendly. Or at least they are friendly with each other.",0);
	add_dialog_str(1,"The moment that you walk in, everyone begins ignoring you with as much vigor as you've ever seen. Only two people seem inclined to talk to you at all: one behind the bar, and one in the northwest corner who is scribbling notes onto a small pad.",0);
	add_dialog_str(2,"The latter greets you from across the room. _Hi,_ he says, _I'm Machrone!_",0);
	set_flag(0,4,run_dialog(1));
	}
break;

beginstate 13;
if (get_flag(0,6) == 0) {
	message_dialog("This appears to be a small classroom. The inn in Pleasant Town must occasionally rent out this room to a school or other educational institution.","You see a small piece of paper advertising _The Review of Prince Town,_ whatever that is.");
	set_flag(0,6,1);
	}
break;

beginstate 14;
	message_dialog("_If you strike me down, I shall become more powerful than you can imagine!!_ the mysterious wizard shouts. You think you've heard that line before, so you swing the killing blow anyway.","Lightning shoots from his fingers!");
	put_jagged_zap(char_loc_x(15),char_loc_y(15),char_loc_x(0),char_loc_y(0),2);
	put_jagged_zap(char_loc_x(15),char_loc_y(15),char_loc_x(1),char_loc_y(1),2);
	put_jagged_zap(char_loc_x(15),char_loc_y(15),char_loc_x(2),char_loc_y(2),2);
	put_jagged_zap(char_loc_x(15),char_loc_y(15),char_loc_x(3),char_loc_y(3),2);
	put_boom_on_char(0,6,0);
	put_boom_on_char(1,6,0);
	put_boom_on_char(2,6,0);
	put_boom_on_char(3,6,0);
	run_animation_sound(54);
	kill_char(1000,2,0);
	message_dialog("Oops. That sucked.","");
break;

beginstate 15;
if (get_flag(0,7)) {
	begin_talk_mode(65);
	end();
	}

	set_flag(0,7,1);
	message_dialog("You approach Machrone to speak to him. He ","");
break;

beginstate 16;
if (get_flag(0,8) == 0)
	end();

if (get_flag(0,9) == 0) {
	message_dialog("You sigh as you pass through these doors. It is abundantly clear that you are done here. Machrone has his orb back, and there are no other worthwhile quests anywhere nearby. It is time to move on.","It is time to continue west, to the Land of Oaks.");
	set_flag(0,9,1);
	}
break;




















